/*
 * @Author: Crism
 * @Date: 2018-08-02 15:45:48
 * @LastEditors: Crism
 * @LastEditTime: 2018-08-10 10:31:15
 * @Description: 
 * @Email: crism@qq.com
 */
const URI = 'https://so.gushiwen.org/authors/Default.aspx?p='
const HttpUtil = require('../util/HttpUtil');
const CommomUtil = require('../libs/CommomUtil');
const authors_m = require('../model/authors_m');

module.exports.getAuthors = getAuthors;
module.exports.getAuthorDetail = getAuthorDetail;
module.exports.getAuthorInfo = getAuthorInfo;

async function getAuthors(ctx) {

    let i = 1;
    let url = URI + i;
    let html = await HttpUtil.httpGet(url);
    let data = [];
    while (i <= 1) {
        console.log('获取第' + i + '页数据。。。');
        let cnt = await authors_m.getAuthors(html, i);
        data.push({
            'page_index': i,
            'content': cnt,
        })
        i++;
        url = URI + i;
        html = await HttpUtil.httpGet(url);
    }


    let resData = {};
    resData['data'] = data;

    return ctx.body = resData;
}

async function getAuthorDetail(ctx) {
    
    let author_detail_url = 'https://so.gushiwen.org//authorv_b90660e3e492.aspx';
    let author_id = 2018000000;

    let cnt = await authors_m.getAuthorDetail(author_detail_url, author_id);


    let resData = {};
    resData['authorDetail'] = cnt;

    return ctx.body = resData;
}

async function getAuthorInfo(ctx) {
    
   
    let cnt = await authors_m.getAuthorInfo();


    let resData = {};
    resData['authorDetail'] = cnt;

    return ctx.body = resData;
}